import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
// 导入全局样式
import '@/style/index.less'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import moment from 'moment/moment'
// 引入echarts
import echarts from 'echarts'
import VueParticles from 'vue-particles'
Vue.use(VueParticles)
Vue.prototype.$echarts = echarts
Vue.use(ElementUI);
Vue.config.productionTip = false
// 过滤器
Vue.filter('formatDate', originVal => {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')
  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')
  return `${y}-${m}-${d}`
})
Vue.filter('formatDateTwo', originVal => {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = dt.getMonth() + 1
  const d = dt.getDate()

  return `${m}-${d}`
})
Vue.filter('formatDateThree', originVal => {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = dt.getDate()
})
// 定时器
Vue.filter('formatDate', originVal => {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')
  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')
  return `${y}-${m}-${d}`
})

Vue.filter('formatDateTwo', originVal => {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = dt.getMonth() + 1
  const d = dt.getDate()

  return `${m}-${d}`
})

Vue.filter('formatDateThree', originVal => {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = dt.getDate()

  return `${y}-${m}`
})

Vue.filter('year', originVal => {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  return `${y}`
})
Vue.filter('month', originVal => {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  return `${y}-${m}`
})
Vue.filter('monthdate', originVal => {
  const dt = new Date(originVal)
  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d =dt.getDate()
  return `${m}-${d}`
})

Vue.filter('week', (val) => {
  let firstDay = new Date(val.getFullYear(), 0, 1)  // 2020-01-01
let dayOfWeek = firstDay.getDay()  // 2020-01-01是周三  dayOfWeek==3
let spendDay = 1
if (dayOfWeek != 0) {
 spendDay = 7 - dayOfWeek + 1   // 5 离下周一还有5天
}
firstDay = new Date(val.getFullYear(), 0, 1 + spendDay)   // 2020-01-06是2020年第一个周一，是2020年第二个周
let d = Math.ceil((val.valueOf() - firstDay.valueOf()) / 86400000)   // 当前时间距离2020-01-06有几天
let result = Math.ceil(d / 7)   // 换算成周为单位 2020-01-06result是0,但其实是第二个周，所以默认加2
let year = val.getFullYear()
let week = result + 1 // 本年第一天是周日，与下个周一在同一周
if (dayOfWeek !== 0) {
   week = result + 2 // 如果使用的是默认为加2（如果将自然周设置为周一到周日则是加1）
}
// console.log(week)
//当年53周改为显示下一年第一周
// val.getDate() !== 26 排除最后一周和下年第一周不在同一周的情况，正常显示53
if (week === 53 && val.getDate() !== 26) {
   week = 1
   year += 1
}
// let startTime = this.$util.dateFormat(val.valueOf() - 86400000)   // 时间戳转字符串，$util是我们封装的方法
// let endTime = this.$util.dateFormat(val.valueOf() + 5*86400000)
// this.weekTime = startTime+'~'+endTime+'  第'+week+'周'   // 2020-05-10~2020-05-16 第20周
let date1=null
if(year===2021){
    date1= year+'-'+(week-1).toString()
}else if(year===2020){
    date1= year+'-'+(week).toString()
}
return date1
})



new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
